import pymysql

class DB:
    def __init__(self):
        self.conn = pymysql.connect(host='localhost',
                                    port=3306,
                                    user='root',
                                    password='root',
                                    charset='utf8',
                                    db='workf',
                                    cursorclass = pymysql.cursors.DictCursor)
        self.cursor = self.conn.cursor()

    #添加，修改，删除
    def insert(self,sql):
        self.cursor.execute(sql)
        self.conn.commit()

    def find(self,sql):
        self.cursor.execute(sql)
        return self.cursor.fetchone()
        # return res

    
    #查询所有数据
    def findall(self,sql):
        #调用游标进行提交
        self.cousor.execute(sql)
        #调用游标查询全部信息
        res=self.cousor.fetchall()
        #返回查询到的结果
        return res


db1 = DB()